package cn.buk.tms.eotms.response;

import cn.buk.tms.common.dto.hotel.BaseHotelOrderDto;
import cn.buk.tms.eotms.dto.HotelOrderPassengerDto;
import cn.buk.tms.eotms.dto.HotelOrderPriceDto;
import cn.buk.tms.eotms.entity.HotelOrder;
import cn.buk.tms.eotms.entity.HotelOrderPassenger;
import cn.buk.tms.eotms.entity.HotelOrderPrice;
import cn.buk.tms.eotms.util.OrderUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 酒店订单DTO
 * Created by yfdai on 2020-05-10
 * @author yfdai
 */
public class HotelOrderResponseDto extends BaseHotelOrderDto {

    public static HotelOrderResponseDto createByHotelOrder(HotelOrder o) {
        HotelOrderResponseDto dto = new HotelOrderResponseDto();

        BeanUtils.copyProperties(o, dto, "passengers", "prices");

        //订单状态
        dto.setOrderStatus(o.getStatus());
        //价格校验状态
        dto.setPriceCheckedStatus(o.getPriceChecked());
        dto.setPriceCheckedTime(o.getPriceCheckedTime());
        //审批相关信息
        OrderUtil.copyApprovalInfo(o.getApprovalInfo(), dto);


        String psgNames = null;
//        logger.info("HotelOrder passengers: " + o.getPassengers().size());
        for (HotelOrderPassenger psg : o.getPassengers()) {
            HotelOrderPassengerDto psgDto = new HotelOrderPassengerDto();

            BeanUtils.copyProperties(psg, psgDto);
            dto.getPassengers().add(psgDto);

            if (psgNames == null) {
                psgNames = psg.getName();
            } else {
                psgNames += "," + psg.getName();
            }
        }

//        logger.info("HotelOrderDto passengers: " + dto.getPassengers().size());

        if (psgNames != null) {
            dto.setPsgCount(dto.getPassengers().size());
            dto.setPassengerName(psgNames);
        }

        if (o.getCustomer() == null) {
            dto.setCustomerId(0);
            dto.setCustomerName("散客");
        } else {
            dto.setCustomerId(o.getCustomerId());
            dto.setCustomerName(o.getCustomer().getVipName());
            dto.setCustomerCode(o.getCustomer().getCustomerCode());
        }

        for(HotelOrderPrice price: o.getPrices()) {
            HotelOrderPriceDto priceDto = new HotelOrderPriceDto();
            BeanUtils.copyProperties(price, priceDto);

            dto.getPrices().add(priceDto);
        }

        return dto;
    }



    //姓名 入住日期 酒店名称 房型 价格 服务费
    /**
     * 姓名
     */
    private String passengerName;

    /**
     * 入住人数
     */
    private int psgCount;

    /**
     * 入住人信息
     */
    private List<HotelOrderPassengerDto> passengers = new ArrayList<>();

    /**
     * 本地酒店系统中的酒店id
     */
    private int hotelId;


    /**
     * 酒店名称
     */
    private String hotelName;

    /**
     * 酒店确认号
     */
    private String supplierConfirmNo;

    /**
     * 本地酒店系统中的售卖房型id
     */
    private int roomId;

    /**
     * 房型
     */
    private String roomType;

    /**
     * 房间数
     */
    private int roomCount;

    /**
     * 入住日期
     */
    @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
    private Date checkInDate;

    /**
     * 离店日期
     */
    @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
    private Date checkOutDate;

    /**
     * 价格/间夜
     */
    private double price;

    /**
     * 服务费
     */
    private double serviceCharge;

    /**
     * 间夜数(房间数*天数）
     */
    private Integer count;

    /**
     * 实收客户总额
     */
    private Double totalAmount;

    /**
     * 每日价格
     */
    @NotNull
    @Size(min = 0, max = 1000)
    private List<HotelOrderPriceDto> prices = new ArrayList<>();

    /**
     * 最晚到店时间
     */
    private String lastArriveTime;

    /**
     * 联系人
     */
    private String linkman;
    /**
     * 联系电话
     */
    private String contactPhone;

    private String remark;

    /**
     * 是否已付款
     */
    private String bePaid;


    /**
     * 保存数据库的时间：系统自动生成
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date createTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date lastUpdate;


    public String getPassengerName() {
        return passengerName;
    }

    public void setPassengerName(String passengerName) {
        this.passengerName = passengerName;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public double getServiceCharge() {
        return serviceCharge;
    }

    public void setServiceCharge(double serviceCharge) {
        this.serviceCharge = serviceCharge;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public void setHotelName(String hotelName) {
        this.hotelName = hotelName;
    }

    public void setRoomType(String roomType) {
        this.roomType = roomType;
    }

    public String getRoomType() {
        return roomType;
    }

    public String getHotelName() {
        return hotelName;
    }

    public String getBePaid() {
        return bePaid;
    }

    public void setBePaid(String bePaid) {
        this.bePaid = bePaid;
    }

    public int getRoomCount() {
        return roomCount;
    }

    public void setRoomCount(int roomCount) {
        this.roomCount = roomCount;
    }

    public int getCount() {
        return count == null ? 1 : count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public double getTotalAmount() {
        return totalAmount == null ? 0 : totalAmount;
    }

    public void setTotalAmount(Double totalAmount) {
        this.totalAmount = totalAmount;
    }

    public Date getLastUpdate() {
        return lastUpdate;
    }

    public void setLastUpdate(Date lastUpdate) {
        this.lastUpdate = lastUpdate;
    }

    public Date getCheckInDate() {
        return checkInDate;
    }

    public void setCheckInDate(Date checkInDate) {
        this.checkInDate = checkInDate;
    }

    public Date getCheckOutDate() {
        return checkOutDate;
    }

    public void setCheckOutDate(Date checkOutDate) {
        this.checkOutDate = checkOutDate;
    }

    public List<HotelOrderPassengerDto> getPassengers() {
        if (this.passengers == null) {
            this.passengers = new ArrayList<>();
        }
        return passengers;
    }

    public void setPassengers(List<HotelOrderPassengerDto> passengers) {
        this.passengers = passengers;
    }

    public int getPsgCount() {
        return psgCount;
    }

    public void setPsgCount(int psgCount) {
        this.psgCount = psgCount;
    }

    public String getLastArriveTime() {
        return lastArriveTime;
    }

    public void setLastArriveTime(String lastArriveTime) {
        this.lastArriveTime = lastArriveTime;
    }

    public List<HotelOrderPriceDto> getPrices() {
        if (prices == null) {
            prices = new ArrayList<>();
        }
        return prices;
    }

    public void setPrices(List<HotelOrderPriceDto> prices) {
        this.prices = prices;
    }

    public int getHotelId() {
        return hotelId;
    }

    public void setHotelId(int hotelId) {
        this.hotelId = hotelId;
    }

    public int getRoomId() {
        return roomId;
    }

    public void setRoomId(int roomId) {
        this.roomId = roomId;
    }

    public String getSupplierConfirmNo() {
        return supplierConfirmNo;
    }

    public void setSupplierConfirmNo(String supplierConfirmNo) {
        this.supplierConfirmNo = supplierConfirmNo;
    }

    public String getLinkman() {
        return linkman;
    }

    public void setLinkman(String linkman) {
        this.linkman = linkman;
    }

    public String getContactPhone() {
        return contactPhone;
    }

    public void setContactPhone(String contactPhone) {
        this.contactPhone = contactPhone;
    }
}
